<template>
  <div>
    <div v-show="! (isShowDetail || isShowAccounModel)">
      <jxf-titletip :title="title" @refreshPage="refreshFuc"></jxf-titletip>
      <el-card class="mt20">
        <el-form :inline="true" :model="searchInfo" ref="searchInfo">
          <el-form-item label="供应商账号:" prop="telphone">
            <el-input v-model.trim="searchInfo.telphone" clearable ref="input-telphone" @keyup.enter.native="enterNextInput('enterpriseName')"></el-input>
          </el-form-item>
          <el-form-item label="企业名称:" prop="enterpriseName">
            <el-input v-model.trim="searchInfo.enterpriseName" clearable ref="input-enterpriseName" @keyup.enter.native="enterNextInput('name')"></el-input>
          </el-form-item>
          <el-form-item label="门店名称:" prop="name">
            <el-input v-model.trim="searchInfo.name"  ref="input-name" clearable @keyup.enter.native="enterNextInput('salesmanName')"></el-input>
          </el-form-item>
          <el-form-item label="账号状态:" prop="status">
            <el-select v-model="searchInfo.status" clearable placeholder="全部">
              <el-option label="禁用" value="0"></el-option>
              <el-option label="启用" value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所属分公司:" prop="agentId">
            <el-select v-model="searchInfo.agentId" clearable placeholder="全部" @focus="getBranchList">
              <el-option :label="agents.userName" :value="agents.id" v-for="(agents, index) in branchList" :key="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="对接业务员:" prop="salesmanName">
            <el-input v-model.trim="searchInfo.salesmanName" clearable ref="input-salesmanName" @keyup.enter.native="onSearch"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSearch()">搜索</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="info" @click="resetForm('searchInfo')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <el-card class="jxf-table-card mt20">
        <div slot="header" class="clearfix">
          <span>数据列表</span>
          <div>
            <el-button type="primary" @click="exportExcel" :loading="isSuccess">导出为Excel</el-button>
          </div>
        </div>
        <jxf-table class="" :table="dataTable">
          <template slot="status" slot-scope="supplier">
            <div>{{supplier.row.status === 0 ? "禁用" : "启用"}}</div>
          </template>
          <template slot="operation" slot-scope="supplier">
            <el-button type="text" @click="showSetting(supplier.row)">查看详情</el-button>
            <el-button type="text" @click="abledBuyer(supplier.row)" v-if="supplier.row.status === 0" class="c-red">启用</el-button>
            <el-button type="text" @click="disabledBuyer(supplier.row)" v-else class="c-red">禁用</el-button>
            <el-button type="text" @click="watchAccountInfo(supplier.row)">查看账户信息</el-button>
          </template>
        </jxf-table>
      </el-card>
      <jxf-pagination class="mt20" :pageTotal="pageTotal" :currentPage.sync='currentPage' :pageSize.sync="pageSize"
                      @currentPageChange="currentPageChange" @pageSizeChange="pageSizeChange"></jxf-pagination>
    </div>
    <DisableBuyer :isShowDetail.sync="isShowDisableBuyer" :dataInfo="disableInfo" :url="supplierUrl" :id="supplierId" @fresh="fresh" title="禁用供应商"></DisableBuyer>
    <AbleBuyer :isShowDetail.sync="isShowAbleBuyer" :dataInfo="ableInfo" :url="supplierUrl" :id="supplierId" @fresh="fresh" title="启用供应商"></AbleBuyer>
    <SupplerReview v-if="isShowDetail" :title="subTitle" @goBack="goBack" :dataInfo="subDataInfo" @goPrewView="goPrewView" @fresh="fresh"></SupplerReview>
  </div>
</template>

<script>
  import DisableBuyer from './components/DisableBuyer'
  import AbleBuyer from './components/AbleBuyer'
  import SupplerReview from './components/SupplerReview'
    export default {
        name: "SupplierList",
        components: {  DisableBuyer, AbleBuyer, SupplerReview },
        data() {
          return {
            title: "供应商列表",
            isShowDetail: false,
            isShowSetting: false,
            // 显示供应商资金账户列表
            isShowAccounModel: false,
            isShowDisableBuyer: false,
            isShowAbleBuyer: false,
            supplierUrl: apis.user.supplierStatus,
            supplierId: 0,
            disableInfo: {},
            branchList: [],
            ableInfo: {},
            searchInfo: {
              telphone: "",
              agentId: "",
              salesmanName: "",
              enterpriseName: "",
              name: "",
              status: ""
            },
            isSuccess: false,
            subDataInfo: {},
            subTitle: "",
            dataTable: {
              border:true,
              loading:false,
              hasSelect:false,
              tr: [
                {
                  id: '2',
                  label: '供应商账号',
                  fixed: "left",
                  width: '120',
                  prop: 'telphone'
                },
                {
                  id: '3',
                  label: '供应商企业名称',
                  minWidth: '140',
                  prop: 'enterpriseName'
                },
                {
                  id: '4',
                  minWidth: '140',
                  label: '供应商门店名称',
                  prop: 'name'
                },
                {
                  id: '5',
                  label: '经营行业',
                  prop: 'businessIndustrys'
                },
                {
                  id: '6',
                  minWidth: '100',
                  label: '所属分公司',
                  prop: 'agentName'
                },
                {
                  id: '7',
                  minWidth: '100',
                  label: '对接业务员',
                  prop: 'salesmanName'
                },
                {
                  id: '8',
                  label: '账号状态',
                  show: 'template',
                  width: '80',
                  prop: 'status'
                },
                {
                  id: '9',
                  label: '操作',
                  show: 'template',
                  fixed: "right",
                  minWidth: "160",
                  prop: 'operation'
                }
              ],
              data: []
            },
            pageTotal:0,
            pageSize:10,
            currentPage:1
          }
        },
        methods: {
          // 返回当前页面
          goPrewView() {
            this.isShowDetail = false;
            this.getData()
          },
          // 导出
          exportExcel() {
            this.isSuccess = true;
            let data = {
              ...this.searchInfo
            };
            ajax.export(apis.user.exportSupplierMannageExcel, data).then((res) => {
              this.isSuccess = false;
              if(res.code) {
                if(res.code === "10000000") {

                } else {
                  this.$message.error(res.message)
                }
              }
            })
          },
          fresh() {
            this.getData()
          },
          refreshFuc() {
            this.resetForm('searchInfo')
            this.pageSize = 10;
            this.currentPage = 1;
            this.getData()
          },
          // 获取分公司
          getBranchList() {
            let data = {
              userType: '2'
            };
            ajax.post(apis.user.getBranchList, data).then(res => {
              if(res.code === '10000000') {
                this.branchList = res.data.dataList;
              } else {
                this.$message.error(res.message)
              }
            })
          },
          // 详情返回上一页
          goBack() {
            this.getData()
            this.isShowDetail = false;
          },
          getData() {
            this.dataTable.loading = true
            let data = {
              ...this.searchInfo,
              pageNum: this.currentPage,
              pageSize: this.pageSize
            };
            ajax.post(apis.user.getSupplier, data).then(res => {
              if(res.code === '10000000') {
                this.dataTable.data = res.data ? res.data.dataList : [];
                this.pageTotal = res.data ? res.data.total : 0;
              } else {
                this.$message.error(res.message)
              }
              this.dataTable.loading = false
            })
          },
          showSetting(obj) {
            this.subTitle = "供应商详情";
            let data = {
              id: obj.id,
              statusNum: 1,
              status: obj.status,
              userId: obj.userId
            };
            ajax.post(apis.user.getSupplierDetail, data).then(res => {
              if(res.code === "10000000") {
                this.subDataInfo = {
                  status: 0,
                  page: 1,
                  accountStatus: obj.status,
                  telphone: obj.telphone,
                  businessId: res.data.supplierPcVo.businessId,
                  enterpriseName: obj.enterpriseName,
                  identityCard: {
                    value: res.data.supplierPcVo.identityCard ? res.data.supplierPcVo.identityCard : "",
                    isEdit: false
                  },
                  license: {
                    value: res.data.supplierPcVo.license ? res.data.supplierPcVo.license : "",
                    isEdit: false
                  },
                  cityId: res.data.supplierPcVo.cityId,
                  otherQualification: {
                    value: res.data.supplierPcVo.otherQualification ? res.data.supplierPcVo.otherQualification : "",
                    isEdit: false
                  },
                  id: res.data.supplierPcVo.id,
                  supplierId: obj.userId,
                  productClassifyIds: res.data.supplierPcVo.typeId,
                  enterpriseAuthId: res.data.supplierPcVo.enterpriseAuthId,
                  reTimeStart: res.data.supplierPcVo.reTimeStart,
                  reTimeEnd: res.data.supplierPcVo.reTimeEnd,
                  identityCardStart: res.data.supplierPcVo.certificateValidity ? res.data.supplierPcVo.certificateValidity.split('-')[0] : "",
                  identityCardEnd: res.data.supplierPcVo.certificateValidity ? res.data.supplierPcVo.certificateValidity.split('-')[1] : "",
                  deliveryIds: res.data.supplierPcVo.deliveryIds,
                  typeId: res.data.supplierPcVo.typeId,
                  ismain: res.data.supplierPcVo.ismain,
                  userId: res.data.supplierPcVo.userId,
                  supplierInfo: [
                    {
                      label: "门店/logo图片",
                      value: res.data.supplierPcVo.logo,
                      type: 'logo',
                      isEdit: false
                    }, {
                      label: "起批金额（元)",
                      value: res.data.supplierPcVo.upMoney,
                      type: 'batchMoney',
                      isEdit: false
                    }, {
                      label: "供应商主体账号",
                      value: res.data.supplierPcVo.telphone,
                      type: "subjectAccount"
                    }, {
                      label: "起送金额（元）",
                      value: res.data.supplierPcVo.taMoney,
                      type: 'startMoney',
                      isEdit: false
                    }, {
                      label: "企业名称",
                      value: res.data.supplierPcVo.enterpriseName,
                      type: 'companyName',
                      isEdit: false
                    }, {
                      label: "是否开启甩单",
                      value: res.data.supplierPcVo.isFling ? res.data.supplierPcVo.isFling.toString() : res.data.supplierPcVo.isFling ,
                      type: 'isOrder',
                      isEdit: false
                    }, {
                      label: "*门店名称",
                      value: res.data.supplierPcVo.name,
                      type: 'storeName',
                      isEdit: false
                    }, {
                      label: "备货时长",
                      value: res.data.supplierPcVo.stockTime,
                      type: 'stockTime',
                      isEdit: false
                    }, {
                      label: "*门店地址",
                      value: res.data.supplierPcVo.storeAddress,
                      type: 'storeAddress',
                      isEdit: false
                    }, {
                      label: "接单时间",
                      value: "",
                      type: 'orderTime',
                      isEdit: false
                    }, {
                      label: "*配送区域",
                      value: res.data.supplierPcVo.deliveryArea,
                      type: 'deliveryArea',
                      isEdit: false
                    }, {
                      label: "账号状态",
                      value: res.data.supplierPcVo.userStatus,
                      type: 'accountStatus',
                      isEdit: false
                    }, {
                      label: "客服电话",
                      value: res.data.supplierPcVo.contact,
                      type: 'consumerHotline',
                      isEdit: false
                    }, {
                      label: "所属分公司",
                      value: res.data.supplierPcVo.agentName,
                      type: "Branch"
                    }, {
                      label: "*经营行业",
                      value: res.data.supplierPcVo.businessIndustrys,
                      type: 'operatingIndustry',
                      isEdit: false
                    }, {
                      label: "对接业务员",
                      value: res.data.supplierPcVo.salesmanName,
                      type: 'dockingSalesman'
                    }, {
                      label: "*社会代码",
                      value: res.data.supplierPcVo.creditCode,
                      type: "creditCode",
                      isEdit: false
                    }, {
                      label: "所属渠道商",
                      value: res.data.supplierPcVo.channelDealerName,
                      type: 'dockingChannel'
                    }, {
                      label: "*定位地址",
                      value: res.data.supplierPcVo.sadress
                    }, {
                      label: '',
                      value: ''
                    }
                  ],
                  otherInfo: [{
                    label: "*注册主体人的名称",
                    value: res.data.supplierPcVo.registrantName,
                    type: "subjectPerson",
                    isEdit: false
                  }, {
                    label: "*注册主体人身份证号码",
                    value: res.data.supplierPcVo.registrantIdNum,
                    type: "registeredIDNumber",
                    isEdit: false
                  }, {
                    label: "*法人名称",
                    value: res.data.supplierPcVo.legalName,
                    type: "legalName",
                    isEdit: false
                  }, {
                    label: "*法人身份证号码",
                    value: res.data.supplierPcVo.idNumber,
                    type: "identityCard",
                    isEdit: false
                  }, {
                    label: "*法人身份证有效期",
                    value: res.data.supplierPcVo.certificateValidity,
                    type: "certificateValidity",
                    isEdit: false
                  }, {
                    label: "入驻时间",
                    value: res.data.supplierPcVo.auditTime,
                    type: "auditTime"
                  }, {
                    label: "南京银行子账号",
                    value: "",
                    type: "legalIDNumber"
                  }, {
                    label: "华夏银行子账号",
                    value: "",
                    type: "legalIDNumber"
                  }, {
                    label: "预留银行卡所属行",
                    value: "",
                    type: "legalIDNumber",
                    isEdit: false
                  }, {
                    label: "银行卡卡号",
                    value: res.data.supplierPcVo.cardNo,
                    type: "cardNo"
                  }],
                  originalinfo: {

                  },

                };
                this.isShowDetail = true;
              } else {
                this.$message.error(res.message)
              }
            })
          },
          onSearch() {
            this.currentPage = 1;
            this.getData()
          },
          resetForm(formName) {
            this.$refs[formName].resetFields();
          },
          // 禁用供应商
          disabledBuyer(obj) {
            this.supplierId = obj.userId;
            this.disableInfo.name = obj.enterpriseName;
            this.isShowDisableBuyer = true;
          },
          // 解禁供应商
          abledBuyer(obj) {
            this.supplierId = obj.userId;
            this.ableInfo.name = obj.enterpriseName;
            this.isShowAbleBuyer = true;
          },
          // 查看资金账户
          watchAccountInfo(obj) {
            let data = {
              telphone: obj.telphone
            };
            this.$router.push({name: 'supplierCapitalAccount',params: data});
          },
          // 切换页面
          currentPageChange(pageNo) {
            this.currentPage = pageNo;
            this.getData()
          },
          // 切换页面条数
          pageSizeChange(pageNo) {
            this.pageSize = pageNo;
            this.getData()

          },
          // 查看详情
          watchDetail() {

          }
        },
        created() {
          this.onSearch()
        }
    }
</script>

<style scoped>

</style>
